<template>
  <div class="gift">
    <view class="progress">
      <view class="h3">10皇后下棋比赛赢礼品卡</view>
      <view class="h4">活动时间：2024.12.23 ~ 最终解揭晓</view>
      <view class="progress-bar">
        <view
          class="progress-bar-inner"
          :style="{
            width: `${(state.machine_num / state.max_machine_num) * 100}%`,
          }"
        ></view>
      </view>
      <view class="h5">
        <text>已计算可行解：{{ state.machine_num }}</text>
        <text>剩余可行解：{{ state.max_machine_num - state.machine_num }}</text>
      </view>
    </view>

    <image
      class="coupon"
      src="https://images-cloud.qboson.com/miniProgram/%E7%BA%A2%E5%8C%853.gif"
    />

    <view class="btn-group">
      <image
        src="https://images-cloud.qboson.com/miniProgram/activity_personal.png"
        @click="pagePush('/pagesA/activity_records/index')"
      />
      <template v-if="false">
        <view class="btn-center">
          <view class="btn" style="flex: 1" @click="openModalTaskadd">
            <view>量子计算机下棋</view>
            <view style="font-size: 11px; margin-top: 8px">
              今日可算{{ state.task_num }}次
            </view>
          </view>
          <view
            class="btn"
            style="width: 40%"
            @click="pagePush('/pagesA/activity_playchess/index')"
          >
            手动下棋
          </view>
        </view>
        <button open-type="share">
          <image
            src="https://images-cloud.qboson.com/miniProgram/%E9%82%80%E8%AF%B7%E5%A5%BD%E5%8F%8B.gif"
          />
        </button>
      </template>
      <div v-else class="event_ends">活动已结束</div>
    </view>
  </div>
</template>

<script setup lang="ts">
import { useUserStore } from "@/stores";
import state, { maxEnterQuota } from "../useState";

const userStore = useUserStore();
const pagePush = (url: string) => {
  if (userStore.userInfo?.uid) {
    uni.navigateTo({ url });
  } else {
    uni.switchTab({ url: "/pages/my/index" });
  }
};
const openModalTaskadd = () => {
  if (!userStore.userInfo?.uid) {
    uni.switchTab({ url: "/pages/my/index" });
  } else if (state.task_num > 0) {
    state.modalTaskadd = true;
    state.enterQuota = maxEnterQuota.value;
  } else {
    uni.showToast({
      icon: "none",
      title: "您今日量子计算机下棋次数已用完，请明天再来。",
    });
  }
};
</script>

<style scoped lang="scss">
.gift {
  padding: 12px 16px 32px;
  .progress {
    position: relative;
    box-sizing: border-box;
    height: 137px;
    margin: 0 16px;
    padding: 17px 13px 0;
    border-radius: 20px;
    box-shadow: inset 7px 0px 20px 0px rgba(255, 226, 191, 0.6);
    background: linear-gradient(270deg, #ffc986 0%, #fd9869 37%, #f94c3b 70%);
    border: 1px solid #f58a73;
    &::after {
      content: "";
      position: absolute;
      top: -8px;
      right: 0;
      width: 97px;
      height: 78.5px;
      background-image: url(https://images-cloud.qboson.com/miniProgram/activity_gift_back.png);
      background-size: 100% 100%;
    }

    .h3 {
      font-size: 17px;
      font-weight: bold;
      line-height: 100%;
      color: #ffffff;
    }
    .h4 {
      margin-top: 6.5px;
      font-size: 11px;
      line-height: 19px;
      color: #ffffff;
    }
    .progress-bar {
      position: relative;
      height: 11px;
      margin-top: 9px;
      border-radius: 49px;
      background: rgba(255, 255, 255, 0.6);
      border: 0.5px solid #ffffff;
      box-shadow:
        0px 0px 5px 0px #ffc788,
        inset 0px 0px 6px 1px rgba(255, 255, 255, 0.8);

      &::after {
        content: "";
        position: absolute;
        right: -11px;
        top: 50%;
        z-index: 10;
        transform: translate(0, -50%);
        width: 59px;
        height: 42px;
        background-image: url(https://images-cloud.qboson.com/miniProgram/zui_zhong_jie.png);
        background-size: 100% 100%;
      }
      .progress-bar-inner {
        position: relative;
        max-width: 100%;
        height: 100%;
        border-radius: 49px;
        background: linear-gradient(270deg, #ff5533 0%, #ffd52d 100%);
        box-shadow: inset 0px 0px 6px 2px rgba(255, 255, 255, 0.5);
        &::after {
          content: "";
          position: absolute;
          top: 50%;
          right: 0;
          transform: translate(50%, -50%);
          width: 35px;
          height: 35px;
          background-image: url(https://qboson-1326050279.cos.ap-beijing.myqcloud.com/miniProgram/activity_xing.png);
          background-size: 100% 100%;
          animation: keyrotate linear 1s infinite;
          @keyframes keyrotate {
            from {
              transform: translate(50%, -50%) rotate(0deg);
            }
            to {
              transform: translate(50%, -50%) rotate(360deg);
            }
          }
        }
      }
    }
    .h5 {
      display: flex;
      justify-content: space-between;
      margin-top: 9px;
      font-size: 10px;
      line-height: 10px;
      color: #ffffff;
    }
  }

  .coupon {
    display: block;
    width: 100%;
    height: 103px;
    margin: -26px 0 16px;
    border-radius: 20px;
    background: linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.3) 0%,
      rgba(255, 250, 237, 0.9) 100%
    );
    backdrop-filter: blur(30px);
  }

  .btn-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 3px;
    width: 100%;
    height: 57px;
    image {
      width: 63px;
      height: 100%;
    }
    .btn-center {
      flex: 1;
      display: flex;
      height: 100%;
      background-image: url(https://images-cloud.qboson.com/miniProgram/activity_gift_btn.png);
      background-size: 100% 100%;
      position: relative;
      &::before {
        content: "";
        position: absolute;
        left: 0;
        top: 4px;
        width: 100%;
        height: 72.34px;
        background-image: url(https://images-cloud.qboson.com/miniProgram/activity_gift_btn_filter.png);
        background-size: 100% 100%;
      }

      .btn {
        position: relative;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        font-size: 13px;
        line-height: 100%;
        color: #ffffff;
        font-weight: 500;
      }
    }
    button {
      height: 100%;
      margin: 0;
      padding: 0;
      background: none;
      &::after {
        content: none;
      }
    }
    .event_ends {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100%;
      margin-left: 12px;
      background-image: url(https://images-cloud.qboson.com/miniProgram/event_ends_bg.png);
      background-size: 100% 100%;
      font-size: 14px;
      font-weight: 500;
      line-height: 100%;
      color: rgba(0, 0, 0, 0.4);
    }
  }
}
</style>
